
/****** Object:  StoredProcedure [dbo].[web_ins_upd_prot_items]    Script Date: 10/19/2013 09:20:36 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'web_ins_upd_prot_items')
DROP PROCEDURE web_ins_upd_prot_items
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[web_ins_upd_prot_items]
	@X02_data varchar(10)
AS	
BEGIN
	SET NOCOUNT ON
	
	delete from x02_prot where X02_data=cast(@X02_data as date)

 
	DECLARE @kodas_ps varchar(100)
	DECLARE @kaina varchar(100)


	DECLARE MY_CURSOR CURSOR 
	  LOCAL STATIC READ_ONLY FORWARD_ONLY
	FOR 
	SELECT kodas_ps,kaina
	FROM #tt_eilutes

	OPEN MY_CURSOR
	FETCH NEXT FROM MY_CURSOR INTO @kodas_ps,@kaina
	WHILE @@FETCH_STATUS = 0
	BEGIN 

	if (@kaina<>'')
		insert into x02_prot ([X02_data],[X02_kodas_ps],[X02_kaina]) 
		values (@X02_data,@kodas_ps,cast(isnull(@kaina,0) as decimal(12,3)))

	FETCH NEXT FROM MY_CURSOR INTO @kodas_ps,@kaina
	END
	CLOSE MY_CURSOR
	DEALLOCATE MY_CURSOR

 
END

GO



